package com.tbit.uqbike.webmanager.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tbit.uqbike.object.pojo.AccountGif;
import com.tbit.uqbike.object.pojo.vo.AccountGifVO;
import com.tbit.common.entity.view.PageResult;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.AccountGifService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 代理商gif弹窗控制
 *
 * @author yee_
 * @version 1.0
 * @date 2023/3/8 10:47
 */
@RestController
@RequestMapping("/account/gif")
public class AccountGifController {

    @Resource
    private AccountGifService accountGifService;

    /**
     * ota 访问配置分页查询
     *
     * @param page 页码
     * @param size 每页条数
     * @return 。
     */
    @GetMapping("/listPage")
    public Result<PageResult<AccountGif>> listPage(@RequestParam(required = false, defaultValue = "1") Integer page,
                                                   @RequestParam(required = false, defaultValue = "10") Integer size) {
        LambdaQueryWrapper<AccountGif> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderBy(true, false, AccountGif::getGifId);
        PageInfo<AccountGif> pageInfo = PageHelper.startPage(page, size).doSelectPageInfo(() -> accountGifService.list(lambdaQueryWrapper));
        return Result.success(new PageResult<>(page, size, pageInfo.getTotal(), pageInfo.getPages(), pageInfo.getList()));
    }

    /**
     * 新增图片配置
     *
     * @param accountGifVO 。
     * @return 。
     */
    @PostMapping("/add")
    public Result<String> add(@Validated AccountGifVO accountGifVO) {
        accountGifService.save(accountGifVO);
        return Result.success();
    }

    /**
     * 删除配置
     *
     * @param gifId 记录id
     * @return 。
     */
    @DeleteMapping("/delete/{gifId}")
    public Result<String> deleteById(@PathVariable Integer gifId) {
        accountGifService.removeById(gifId);
        return Result.success();
    }

}

